package cn.tedu.knows.faq.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class TimerAspect {

    //定切点
    //通配所有业务逻辑层的接口的方法
    @Pointcut("execution(" +
            "* cn.tedu.knows.faq.service.*Service.*(..))")
    public void serviceCut(){}

    @Around("serviceCut()")
    public Object timer(ProceedingJoinPoint joinPoint)
            throws Throwable {
        long start=System.currentTimeMillis();
        Object ret=joinPoint.proceed();
        long end=System.currentTimeMillis();
        long time=end-start;
        Signature method=joinPoint.getSignature();
        System.out.println(
                method.getName()+"方法耗时"+time+"毫秒");

        return ret;
    }


}
